package com.chenyun.tenant.aop;

import com.chenyun.tenant.TenantContext;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;

import java.io.Serializable;

/**
 * 忽略租户切面 记录{@link TenantIgnore}实现
 * @author: Lonni
 * @date: 2024/5/21 0021 15:13
 */
@Aspect
@Slf4j
@ConditionalOnProperty(value = "chenyun.tenantEnable",havingValue = "true")
public class TenantIgnoreAspect implements Serializable {

    @Around("@annotation(tenantIgnore)")
    public Object around(ProceedingJoinPoint point, TenantIgnore tenantIgnore) throws Throwable {
        log.info("检测到忽略租户注解-------->");
        Boolean ignore = TenantContext.me.ignore();
        try {
            TenantContext.me.setIgnoreTenant(true);
            // 执行逻辑
            return point.proceed();
        } finally {
            TenantContext.me.setIgnoreTenant(ignore);
        }
    }

}



